<?php

namespace app\statistics\controller;

use think\admin\Controller;
use think\admin\helper\QueryHelper;
use app\order\model\ImsEweiShopOrder;
use app\order\model\ImsEweiShopOrderGoods;

class Orders extends Controller
{
    public function index()
    {
        $this->type = $this->get['type'] ?? 3;

        $this->typeList = ['3'=>lang('3天'),'7'=>lang('7天'),'15'=>lang('15天'),'30'=>lang('30天'),'60'=>lang('60天'),'100'=>lang('100天'),'365'=>lang('一年')];
        ImsEweiShopOrder::mQuery()->layTable(function () {
            $this->title = '订单列表';
        }, function (QueryHelper $query) {
            $query->alias('o')->leftJoin('ims_ewei_shop_member sm ','sm.openid = o.openid');
            
            $query->field(" o.*,sm.nickname,max(o.paytime) AS mptime ");
            $query->where('o.paytime>0 AND o.status>0');
            $query->group('o.openid');
            $query->having('mptime<'.time()-86400*$this->type);
            // var_dump($query->buildSql());exit();
        });
        $this->fetch();
    }

    ### 当一个控制器存在多个page操作时，可以指定回调前缀
    protected function _index_page_filter(&$data){
      // 精准回调对 $data 进行二次处理，注意是引用
        foreach ($data as $k => $v) {
            $data[$k]['address'] = unserialize($v['address']);
            $data[$k]['paytypename'] = unserialize($v['address']);
            $data[$k]['paytime'] = date('Y-m-d H:i:s',$v['paytime']);
            $data[$k]['mptime'] = date('Y-m-d H:i:s',$v['mptime']);
            $data[$k]['status'] = ImsEweiShopOrder::orderStatusStr($v['status']);
        }
    }

    public function add()
    {
    }

    public function edit()
    {
    }
}
